package model.vos.reprodutivo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "suino")
@Inheritance(strategy = InheritanceType.JOINED)
public class Suino implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4070597519781552332L;
	/**
	 * 
	 */
	
	private Long id;
	private String identificador;
	private Raca raca;
	private char sexo;
	private Set<Peso> pesagens = new HashSet<Peso>();

	public Suino() {
	}

	public Suino(Long id, String identificador, Raca raca, char sexo,
			Set<Peso> pesagens) {
		super();
		this.id = id;
		this.identificador = identificador;
		this.raca = raca;
		this.sexo = sexo;
		this.pesagens = pesagens;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id_suino", nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "identificador")
	public String getIdentificador() {
		return identificador;
	}

	public void setIdentificador(String identificador) {
		this.identificador = identificador;
	}

	@ManyToOne
	@JoinColumn(name = "raca_id")
	public Raca getRaca() {
		return raca;
	}

	public void setRaca(Raca raca) {
		this.raca = raca;
	}

	@Column(name = "sexo")
	public char getSexo() {
		return sexo;
	}

	public void setSexo(char sexo) {
		this.sexo = sexo;
	}

	@OneToMany(mappedBy = "suino")
	public Set<Peso> getPesagens() {
		return pesagens;
	}

	public void setPesagens(Set<Peso> pesagens) {
		this.pesagens = pesagens;
	}


	@Override
	public String toString() {
		return "Suino [identificador=" + identificador + ", raca=" + raca
				+ ", sexo=" + sexo + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Suino other = (Suino) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
